var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    host:app.globalData.remoteDomain,
    myhost: app.globalData.remoteDomainMy,
    datas: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    wx.request({
      url: app.globalData.remoteDomainApi + 'getuserinfo.php',
      data: {
        openid: app.globalData.openid,
        y: ''
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
        that.setData({
          datas: res.data
        })
      }
    })
  },
/**
 * 扫码
 */
  scan:function(){
    wx.scanCode({
      success(res) {
        console.log(res)

        let code = res.result;

        //获取产品分类和ID
        wx.request({
          url: app.globalData.remoteDomainApi+'scan.php', // 仅为示例，并非真实的接口地址
          data: {
            code: code,
            y: ''
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(res) {
            let catagory = res.data.catagory;

            let pid = res.data.pid;

            if(!catagory || !pid){
              console.log('抱歉，没有该产品')
            }else{
              if (catagory == 'book') {
                wx.navigateTo({
                  url: '../detailBook/detailBook?id=' + pid,
                })
              } else if (catagory == 'music') {
                wx.navigateTo({
                  url: '../detailMusic/detailMusic?id=' + pid,
                })
              } else {
                wx.navigateTo({
                  url: '../detailMovie/detailMovie?id=' + pid,
                })
              }
            }         
          }
        })
      }
    })
  }
})